# @ Time    : 2020/4/2 20:01
# @ Author  : JuRan

import requests
import time
requests.packages.urllib3.disable_warnings()

url = "https://mapi.kyboye.com/news/index?psize=10&skip=0&type=1&schid=&speid=10010104&_t=1585829082915"

header = {
    "Host": "mapi.kyboye.com",
    "Cookie": "FDX_auth=6abc1c09a4T5RZ7VuzD41Hg9YPnkuQXEozOaV19J3di99sG%2FahbNaaSBqSiu%2F0ygPOqDX%2FAF1u3uEF3D10; FDX_auth=6abc1c09a4T5RZ7VuzD41Hg9YPnkuQXEozOaV19J3di99sG%2FahbNaaSBqSiu%2F0ygPOqDX%2FAF1u3uEF3D10; FDX_auth=6abc1c09a4T5RZ7VuzD41Hg9YPnkuQXEozOaV19J3di99sG%2FahbNaaSBqSiu%2F0ygPOqDX%2FAF1u3uEF3D10; FDX_auth=6abc1c09a4T5RZ7VuzD41Hg9YPnkuQXEozOaV19J3di99sG%2FahbNaaSBqSiu%2F0ygPOqDX%2FAF1u3uEF3D10; FDX_sid=w23315666_4d893c97c36de6e10db0f9",
    "User-Agent": "KaoYanBang AipBot/1.0 (KaoYanClub-Android/3.2.9; android/5.1.1; Xiaomi+MI+9)"
}


r = requests.get(url=url, headers=header, verify=False).json()

# print(r)
for item in r['res']['cate']:
    print(item)
    cid = item['id']
    page = 0
    while True:
        try:
            url = "https://mapi.kyboye.com/news/article/list?cid={}&sid=&skip={}&wd=&scid=0&speid=10010104&psize=20&type=1&_t=1585829421305".format(cid, page)
            r1 = requests.get(url, headers=header, verify=False).json()
            for item in r1['res']['list']:
                title = item['title']
                intro = item['intro']
                aid = item['id']
                time.sleep(1)
                url = "https://mapi.kyboye.com/news/article/get?id={}&psize=10&skip=0&_t=1585829997178".format(aid)
                r2 = requests.get(url, headers=header, verify=False).json()
                content = r2['res']['content']
                print(content)
                print("="*30)

            time.sleep(1)
            page += 20
        except Exception as e:
            print(e)
            break





"""
{'id': 203, 'pid': '0', 'name': '报考经验', 'total': 0, 'url': '', 'icon': 'http://img.kaoyan.com/bang/images/app/news_cate_icon/icon_news_cate_203.png?301'}

https://mapi.kyboye.com/news/article/list?cid=203&sid=&skip=0&wd=&scid=0&speid=10010104&psize=20&type=1&_t=1585829421305

https://mapi.kyboye.com/news/article/list?cid=203&sid=&skip=20&wd=&scid=0&speid=10010104&psize=20&type=1&_t=1585829484505

https://mapi.kyboye.com/news/article/list?cid=203&sid=&skip=40&wd=&scid=0&speid=10010104&psize=20&type=1&_t=1585829519152


{'id': 1017, 'pid': '201', 'name': '政策新闻', 'total': 0, 'url': '', 'icon': 'http://img.kaoyan.com/bang/images/app/news_cate_icon/icon_news_cate_201.png?301'}
{'id': 204, 'pid': '0', 'name': '考研心路', 'total': 0, 'url': '', 'icon': 'http://img.kaoyan.com/bang/images/app/news_cate_icon/icon_news_cate_204.png?301'}
{'id': '13', 'pid': '0', 'name': '公共课复习', 'total': '0', 'url': '', 'icon': 'http://img.kaoyan.com/bang/images/app/news_cate_icon/icon_news_cate_13.png?301'}
{'id': 211, 'pid': '0', 'name': '复试调剂', 'total': 0, 'url': '', 'icon': 'http://img.kaoyan.com/bang/images/app/news_cate_icon/icon_news_cate_211.png?301'}
"""


